home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Grafik / Misc / netpbm / bin / pnminterp-gen < prev    next >
Encoding:
Text File  |  2000-01-01  |  1.2 KB  |  52 lines

  1. #!/bin/sh
  2. #
  3. # pnminterp-gen - a shell script which acts a little like a general
  4. #     form of pnminterp, by scaling up with pnminterp then scaling
  5. #     down with pnmscale.
  6. #
  7. # it also copes with N<1, but then it just uses pnmscale. :-)
  8.  
  9. if [ "$1" = "" ]; then
  10.   echo 'usage: pnminterp-gen N [pnmfile]'
  11.   exit 1
  12. fi
  13.  
  14. tempfile=/tmp/pnmig$$
  15. trap 'rm -f $tempfile' 0 1 3 15
  16.  
  17. if ! cat $2 >$tempfile 2>/dev/null; then
  18.   echo 'pnminterp-gen: error reading file' 1>&2
  19.   exit 1
  20. fi
  21.  
  22. # we use the width as indication of how much to scale; width and
  23. # height are being scaled equally, so this should be ok.
  24. width=`pnmfile $tempfile 2>/dev/null|cut -d " " -f 3`
  25.  
  26. if [ "$width" = "" ]; then
  27.   echo 'pnminterp-gen: not a PNM file' 1>&2
  28.   exit 1
  29. fi
  30.  
  31. # should really use dc for maths, but awk is less painful :-)
  32. target_width=`awk 'BEGIN{printf("%d",'0.5+"$width"*"$1"')}'`
  33.  
  34. # work out how far we have to scale it up with pnminterp so that the
  35. # new width is >= the target width.
  36. int_scale=`awk '
  37. BEGIN {
  38. int_scale=1;int_width='"$width"'
  39. while(int_width<'"$target_width"')
  40.   {
  41.   int_scale++
  42.   int_width+='"$width"'
  43.   }
  44. print int_scale
  45. }'`
  46.  
  47. if [ "$int_scale" -eq 1 ]; then
  48.   pnmscale "$1" $tempfile
  49. else
  50.   pnminterp "$int_scale" $tempfile | pnmscale -xsi "$target_width"
  51. fi
  52.